package Main;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import Army.building.BuildingMine;
import Army.building.BuildingHouse;
import Army.building.BuildingBarrack;
import Army.building.Building;
import Army.building.BuildingCastle;
import Army.building.BuildingFactory;
import Army.BuildingAndUnit;
import Army.unit.UnitSwordMan;
import Army.unit.UnitSpearMan;
import Army.unit.UnitArcher;
import Army.unit.Unit;
import Army.unit.UnitWorker;
import AIproccess.AIManager;
import Army.*;
import Component.MyButton;
import Component.MyForm;
import Component.MyLabel;
import Component.MyPanel;
import Component.MyTextBox;
import Component.MyTextButton;
import GameObject.ImageObject;
import GameObject.LayerManager;
import GameObject.Sprite;
import Global.GlobalGameOption;
import Global.ResourceManager;
import MOM.Center;
import MOM.Message;
import MOM.Subcriber;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Alvis
 */
public class GamePlayState extends GameState implements Subcriber {

	private LayerManager layerManager;
	private AIManager aiManager;
	private boolean isInterrupted;
	Sprite cursor;
	private Point currentMousePosition;
	private Point pressedMousePosition;
	private boolean isMousePressed;
	private int dx = 0;
	private int dy = 0;
	int messageTimeLeft = 0;
	boolean isImmortal = false;
	int groupNumber;
	boolean PrepareGroup;
	Group currentSelectedGroup;
	PlayerTeam myTeam;
	ComputerTeam[] comTeams;
	Building selectingBuilding;
	InfoPanel infoPanlel;
	MyLabel teamPopLabel;
	MyLabel teamGoldLabel;
	MyPanel confirmPanel;
	MyPanel subMiniMap;
	MyPanel workerPanel;
	MyPanel barrackPanel;
	MyPanel castlePanel;
	MyButton barrackButton;
	MyButton houseButton;
	MyButton mineButton;
	MyButton archerButton;
	MyButton workerButton;
	MyButton spearButton;
	MyButton swordButton;
	MyPanel armorPanel;
	MyPanel damagePanel;
	MyLabel armorLabel;
	MyLabel damageLabel;
	MyLabel hpPanel;
	MyLabel hpLabel;
	MyPanel infoUnit;
	MyLabel messageLabel;
	MyTextBox cheatBox;

	public GamePlayState(Game _game, LayerManager lm, PlayerTeam mTeam, ComputerTeam[] cTeams, AIManager ai, boolean allowCheat) {
		super(_game);
		PrepareGroup = false;
		layerManager = lm;
		myTeam = mTeam;
		comTeams = cTeams;
		form = new MyForm(ResourceManager.getImage("ingame/background"), game.getWidth(), game.getHeight());
		MyPanel miniMap = new MyPanel(layerManager.getMap().getTinyMap(), 200, 200, 600, 0);

		teamPopLabel = new MyLabel("", 500, 2);
		teamPopLabel.setForeColor(Color.WHITE);
		teamGoldLabel = new MyLabel("", 410, 2);
		teamGoldLabel.setForeColor(Color.WHITE);

		messageLabel = new MyLabel("Message :", 25, 2);
		messageLabel.setForeColor(Color.YELLOW);

		workerPanel = new MyPanel(200, 300, new Color(0, true), 610, 470);
		barrackPanel = new MyPanel(200, 300, new Color(0, true), 610, 470);
		castlePanel = new MyPanel(200, 300, new Color(0, true), 610, 470);

		infoUnit = new MyPanel(200, 300, new Color(0, true), 598, 354);

		houseButton = new MyButton(ResourceManager.getImage("button/house"), 0, 0);
		houseButton.setToolTipText(BuildingHouse.BUILD_COST + "G");
		barrackButton = new MyButton(ResourceManager.getImage("button/barrack"), 120, 0);
		barrackButton.setToolTipText(BuildingBarrack.BUILD_COST + "G");
		mineButton = new MyButton(ResourceManager.getImage("button/mine"), 60, 0);
		mineButton.setToolTipText(BuildingMine.BUILD_COST + "G");

		archerButton = new MyButton(ResourceManager.getImage("button/archer"), 0, 0);
		archerButton.setToolTipText(UnitArcher.BUILD_COST + "G");
		spearButton = new MyButton(ResourceManager.getImage("button/spearman"), 60, 0);
		spearButton.setToolTipText(UnitSpearMan.BUILD_COST + "G");
		swordButton = new MyButton(ResourceManager.getImage("button/swordman"), 120, 0);
		swordButton.setToolTipText(UnitSwordMan.BUILD_COST + "G");

		workerButton = new MyButton(ResourceManager.getImage("button/worker"), 0, 0);
		workerButton.setToolTipText(UnitWorker.BUILD_COST + "G");

		damagePanel = new MyPanel(ResourceManager.getImage("icon/damage"), 50, 30, 20, -60);
		armorPanel = new MyPanel(ResourceManager.getImage("icon/defend"), 50, 30, 110, -60);

		infoPanlel = new InfoPanel(610, 390, 180, 60);
		cheatBox = new MyTextBox(ResourceManager.getImage("ingame/textbar"), "", 50, 578);

		final int wMap = layerManager.getMap().getWidth();
		final int hMap = layerManager.getMap().getHeight();

		form.add(miniMap);
		form.add(workerPanel);
		form.add(barrackPanel);
		form.add(castlePanel);
		form.add(teamPopLabel);
		form.add(teamGoldLabel);
		form.add(infoUnit);
		form.add(messageLabel);
		form.add(infoPanlel);
		MyButton exitButton = new MyButton(ResourceManager.getImage("ingame/exit"), 5, 5);
		exitButton.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				isInterrupted = true;
				confirmPanel.setVisible(true);
			}
		});
		form.add(exitButton);
		if (allowCheat) {
			cheatBox.setMaxChar(100);
			cheatBox.setKeyAdapter(new KeyAdapter() {
				@Override
				public void keyPressed(KeyEvent e) {

					int key = e.getKeyCode();
					if (key == KeyEvent.VK_ENTER) {
						String str = cheatBox.getText();
						cheatBox.setText("");
						exeCheat(str);
					}
				}
			});
			form.add(cheatBox);
		}

		workerPanel.add(barrackButton);
		workerPanel.add(mineButton);
		workerPanel.add(houseButton);

		barrackPanel.add(spearButton);
		barrackPanel.add(swordButton);
		barrackPanel.add(archerButton);

		castlePanel.add(workerButton);

		damageLabel = new MyLabel("", 70, -60);
		armorLabel = new MyLabel("", 160, -60);
		hpPanel = new MyLabel("HP: ", 30, -20);
		hpLabel = new MyLabel("", 60, -20);

		infoUnit.add(damagePanel);
		infoUnit.add(armorPanel);
		infoUnit.add(damageLabel);
		infoUnit.add(armorLabel);
		infoUnit.add(hpPanel);
		infoUnit.add(hpLabel);


		workerPanel.setVisible(false);
		castlePanel.setVisible(false);
		barrackPanel.setVisible(false);
		infoUnit.setVisible(false);


		initConfirmPanel();
		isMousePressed = false;
		currentMousePosition = new Point(20, 20);
		aiManager = ai;
		aiManager.start();


		currentSelectedGroup = new Group(true);
		isInterrupted = false;

		subMiniMap = new MyPanel(layerManager.getMiniMap(), 200, 200, 0, 0);
		subMiniMap.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				Rectangle r = subMiniMap.getSprite().getBound();
				int x = (e.getX() - r.x) * wMap / r.width - game.getHeight() / 2;
				int y = (e.getY() - r.y) * hMap / r.height - game.getHeight() / 2;
				layerManager.setViewPoint(x, y);
			}
		});
		miniMap.add(subMiniMap);

		cursor = new Sprite(ResourceManager.getImage("ingame/cursor"), 5, 1, 0, 0);
		cursor.setInnerPoint(new Point(25, 25));
		cursor.setSequence(0);
		GlobalGameOption.SOUND.getSound("game").loop();
	}

	public LayerManager getLayerManager() {
		return layerManager;
	}

	public Unit getSelectedUnit(Point endPoint, ArrayList<Unit> array) {
		for (Iterator<Unit> it = array.iterator(); it.hasNext();) {
			Unit army = it.next();
			if (ImageObject.isIn(endPoint, army.getBound())) {
				return army;
			}
		}
		return null;
	}

	public Building getSelectedBuilding(Point endPoint, ArrayList<Building> array) {
		for (Iterator<Building> it = array.iterator(); it.hasNext();) {
			Building army = it.next();
			if (ImageObject.isIn(endPoint, army.getBound())) {
				return army;
			}
		}
		return null;
	}

	private void initConfirmPanel() {
		confirmPanel = new MyPanel(250, 100, Color.GRAY, 250, 200);
		form.add(confirmPanel);
		MyTextButton bOk = new MyTextButton("Yes", 20, 50);
		confirmPanel.add(bOk);
		MyTextButton bCancel = new MyTextButton("No", 130, 50);
		confirmPanel.add(bCancel);
		MyLabel msgLabel = new MyLabel("Exit current game ?", 70, 20);
		msgLabel.setForeColor(Color.WHITE);
		confirmPanel.add(msgLabel);

		confirmPanel.setVisible(false);
		bOk.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				Center.topics.clear();
				endGame(new GameMenuState(game));
			}
		});
		bCancel.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				confirmPanel.setVisible(false);
				isInterrupted = false;
			}
		});

		barrackButton.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				createBuilding("barrack");
			}
		});
		mineButton.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				createBuilding("mine");
			}
		});
		houseButton.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				createBuilding("house");
			}
		});


		swordButton.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				createUnit("swordman");
			}
		});

		spearButton.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				createUnit("spearman");
			}
		});

		archerButton.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				createUnit("archer");
			}
		});

		workerButton.setMouseAdapter(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				createUnit("worker");
			}
		});
	}
	int count = 0;

	public void createBuilding(String type) {
		layerManager.setPreBuilding(BuildingFactory.createBuilding(type, myTeam.getTeamId(), 0, 0));
	}

	public void createUnit(String type) {
		if (selectingBuilding != null) {
			myTeam.createNewUnit(type, selectingBuilding);
		}
	}

	@Override
	public void update(float t) {

		teamGoldLabel.setText("G : " + myTeam.getGold());
		teamPopLabel.setText("P : " + myTeam.getPopulation()
				+ "/" + +myTeam.getPopulationLimit());
		if (isInterrupted) {
			return;
		}
		int w = game.getWidth();
		int h = game.getHeight();

		layerManager.update();
		layerManager.updatePreBuildingPosition(layerManager.window2Local(currentMousePosition));
		subMiniMap.setImage(layerManager.getMiniMap());

		if (messageTimeLeft == 0) {
			messageLabel.setText("Message :");
		} else {
			messageTimeLeft--;
		}

		infoPanlel.setBuilding(selectingBuilding);

		barrackPanel.setVisible(false);
		castlePanel.setVisible(false);
		if (selectingBuilding != null && selectingBuilding.isCompleted()) {
			if (selectingBuilding.getType() == BuildingAndUnit.Type.BuildingBarrack) {
				barrackPanel.setVisible(true);
			} else if (selectingBuilding.getType() == BuildingAndUnit.Type.BuildingCastle) {
				castlePanel.setVisible(true);
			}
		}
		if (currentSelectedGroup.getListUnit().size() == 1) {
			BuildingAndUnit unit = currentSelectedGroup.getListUnit().get(0);
			if (unit.isAlive()) {
				hpLabel.setText(unit.getHealthPoint() + "/" + unit.getMaxHealthPoint());
			} else {
				hpLabel.setText("");
			}
		}

		if (Math.random() > 0.95) {
			if (!myTeam.isAlive()) {
				if (!isImmortal) {
					endGame(new GameStateEnd(game, false));
				}
			} else {
				boolean win = true;
				for (int i = 0; i < layerManager.getListTeam().length; i++) {
					PlayerTeam team = layerManager.getListTeam()[i];
					if (!team.isIsControled() && team.isAlive()) {
						win = false;
						break;
					}
				}
				if (win) {
					endGame(new GameStateEnd(game, true));
				}
			}
		}
		int scrollSpeed = 30;

		if (w - currentMousePosition.x < 5) {
			dx = (int) (scrollSpeed);

		} else if (currentMousePosition.x < 5) {
			dx = (int) (-scrollSpeed);
		} else {
			dx = 0;
		}
		if (h - currentMousePosition.y < 5) {
			dy = (int) (scrollSpeed);
		} else if (currentMousePosition.y < 5) {
			dy = (int) (-scrollSpeed);
		} else {
			dy = 0;
		}

		layerManager.move(dx, dy);
	}

	@Override
	public void draw(Graphics2D g) {
		g.setColor(Color.WHITE);
		layerManager.draw(g);
		g.setTransform(new AffineTransform());
		g.setColor(Color.WHITE);
		if (isMousePressed) {
			Point startPoint = layerManager.local2Window(pressedMousePosition);

			int x0 = Math.min(startPoint.x, currentMousePosition.x);
			int y0 = Math.min(startPoint.y, currentMousePosition.y);
			int w = Math.abs(currentMousePosition.x - startPoint.x);
			int h = Math.abs(currentMousePosition.y - startPoint.y);

			g.drawRect(x0, y0, w, h);
		}
		form.draw(g);
	}

	@Override
	public void keyPressed(KeyEvent e) {
		super.keyPressed(e);
		int key = e.getKeyCode();


		if (key == KeyEvent.VK_LEFT) {
			dx = -100;
		}

		if (key == KeyEvent.VK_RIGHT) {
			dx = 100;
		}

		if (key == KeyEvent.VK_UP) {
			dy = -100;
		}

		if (key == KeyEvent.VK_DOWN) {
			dy = 100;
		}
		if (key == KeyEvent.VK_CONTROL) {
			PrepareGroup = true;
		}
		if (key == KeyEvent.VK_ENTER) {
			if (cheatBox != null) {
				if (cheatBox.isForcus()) {
					cheatBox.lostForcus();
				} else {
					cheatBox.setForcus();
				}
			}
		}
		if (key == KeyEvent.VK_1) {
			groupNumber = 1;
		}
		if (PrepareGroup == true && groupNumber == 1) {

			myTeam.setGroupNumber(1);
		}
		layerManager.move(dx, dy);
	}

	@Override
	public void keyReleased(KeyEvent e) {
		super.keyReleased(e);
		int key = e.getKeyCode();
		if (key == KeyEvent.VK_ESCAPE) {
			isInterrupted = true;
			confirmPanel.setVisible(true);
		}
		if (key == KeyEvent.VK_CONTROL) {
			PrepareGroup = false;
		}
		if (key == KeyEvent.VK_1) {

			currentSelectedGroup.clear();
			myTeam.getSelectGroup(1);
			for (int i = 0; i < myTeam.getListUnit().size(); i++) {
				if (myTeam.getListUnit().get(i).getGroupNumber() == 1) {
					currentSelectedGroup.add(myTeam.getListUnit().get(i));
				}
			}
			HandlePanel();
		}
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		super.mouseDragged(e);
		currentMousePosition = e.getPoint();
	}

	@Override
	public void notify(Message msg) {
		if (msg.message.equalsIgnoreCase("completed")) {
			setMessage(((BuildingAndUnit) msg.object).getType() + " is completed");
		} else if (msg.message.equalsIgnoreCase("attacked")) {
			setMessage("We are under attack");
		}
	}

	private void setMessage(String str) {
		messageTimeLeft = 100;
		messageLabel.setText("Message : " + str);
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		super.mouseMoved(e);

		if (e.getX() < game.getHeight()) {
			isMousePressed = false;
		}
		currentMousePosition = e.getPoint();
	}

	@Override
	public void mousePressed(MouseEvent e) {
		super.mousePressed(e);
		if (e.getX() > 600*form.getScaleX()) {
			return;
		}
		if (e.getButton() == MouseEvent.BUTTON1) {



			pressedMousePosition = layerManager.window2Local(e.getPoint());
			isMousePressed = true;
			Building building = layerManager.donePreBuilding();
			if (building == null) {
				currentSelectedGroup.clear();
			} else if (myTeam.add(building)) {
				//todo:
				building.startBuild();
				currentSelectedGroup.setTarget(building);
			} else {
				setMessage("Not enough money");
			}
		}
		if (e.getButton() == MouseEvent.BUTTON3) {

			pressedMousePosition = layerManager.window2Local(e.getPoint());
			isMousePressed = true;
			Building building = layerManager.donePreBuilding();

		}

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		super.mouseReleased(e);
		Point endPoint = layerManager.window2Local(currentMousePosition);
		isMousePressed = false;
		if (e.getX() < 600*form.getScaleX() && e.getButton() == MouseEvent.BUTTON3) {
			BuildingAndUnit army = getSelectedUnit(endPoint, myTeam.getListUnit());
			if (army != null) {
				currentSelectedGroup.setTarget(army);
				return;
			}
			army = getSelectedBuilding(endPoint, myTeam.getListBuilding());
			if (army != null) {
				currentSelectedGroup.setTarget(army);
				return;
			}

			for (int i = 0; i < comTeams.length; i++) {
				army = getSelectedUnit(endPoint, comTeams[i].getListUnit());
				if (army != null) {
					currentSelectedGroup.setTarget(army);
					return;
				}
				army = getSelectedBuilding(endPoint, comTeams[i].getListBuilding());
				if (army != null) {
					currentSelectedGroup.setTarget(army);
					return;
				}
			}
			cursor.setPosition(endPoint);

			layerManager.addEffect(cursor);
			currentSelectedGroup.setTarget(endPoint);

		} else if (pressedMousePosition != null && e.getButton() == MouseEvent.BUTTON1) {
			selectUnit();
			if (e.getClickCount() == 2) {
				selectSameUnit();
			}
			pressedMousePosition = null;
		}
	}

	private void selectSameUnit() {
		Point endPoint = layerManager.window2Local(currentMousePosition);
		int x0 = Math.min(pressedMousePosition.x, endPoint.x);
		int y0 = Math.min(pressedMousePosition.y, endPoint.y);
		int w = Math.abs(endPoint.x - pressedMousePosition.x);
		int h = Math.abs(endPoint.y - pressedMousePosition.y);
		if (w < 2 && h < 2) {
			for (Iterator<Unit> it = myTeam.getListUnit().iterator(); it.hasNext();) {
				Unit army = it.next();
				if (ImageObject.isIn(pressedMousePosition, army.getBound())) {
					currentSelectedGroup.add(army);
					for (int i = 0; i < myTeam.getListUnit().size(); i++) {
						if (myTeam.getListUnit().get(i).getType() == army.getType()) {
							Unit unit = myTeam.getListUnit().get(i);
							currentSelectedGroup.add(unit);
						}
					}
					break;
				}
			}
		} else {
			for (Iterator<Unit> it = myTeam.getListUnit().iterator(); it.hasNext();) {
				Unit army = it.next();
				if (ImageObject.isIn(army.getPosition(), new Rectangle(x0, y0, w, h))) {
					currentSelectedGroup.add(army);
					for (int i = 0; i < myTeam.getListUnit().size(); i++) {
						if (myTeam.getListUnit().get(i).getType() == army.getType()) {
							Unit unit = myTeam.getListUnit().get(i);
							currentSelectedGroup.add(unit);
						}

					}
				}
			}
		}

	}

	private void selectUnit() {
		Point endPoint = layerManager.window2Local(currentMousePosition);
		int x0 = Math.min(pressedMousePosition.x, endPoint.x);
		int y0 = Math.min(pressedMousePosition.y, endPoint.y);
		int w = Math.abs(endPoint.x - pressedMousePosition.x);
		int h = Math.abs(endPoint.y - pressedMousePosition.y);
		if (w < 2 && h < 2) {
			for (Iterator<Unit> it = myTeam.getListUnit().iterator(); it.hasNext();) {
				Unit army = it.next();
				if (ImageObject.isIn(pressedMousePosition, army.getBound())) {
					currentSelectedGroup.add(army);
					break;
				}
			}

			if (currentSelectedGroup.isEmpty()) {
				for (Iterator<Building> it = myTeam.getListBuilding().iterator(); it.hasNext();) {
					Building army = it.next();

					if (ImageObject.isIn(endPoint, army.getBound())) {
						currentSelectedGroup.add(army);
						break;
					}
				}
			}
		} else {
			for (Iterator<Unit> it = myTeam.getListUnit().iterator(); it.hasNext();) {
				Unit army = it.next();
				if (ImageObject.isIn(army.getPosition(), new Rectangle(x0, y0, w, h))) {
					currentSelectedGroup.add(army);
				}
			}
			if (currentSelectedGroup.isEmpty()) {
				for (Iterator<Building> it = myTeam.getListBuilding().iterator(); it.hasNext();) {
					Building army = it.next();
					if (ImageObject.isIn(army.getPosition(), new Rectangle(x0, y0, w, h))) {
						currentSelectedGroup.add(army);
						break;
					}
				}
			}

		}
		if (currentSelectedGroup.isUnit()) {
			GlobalGameOption.SOUND.getSound("speak").start();
		}
		HandlePanel();

	}

	public void HandlePanel() {
		selectingBuilding = null;
		if (currentSelectedGroup.getListUnit().size() == 1) {
			infoUnit.setVisible(true);

			damageLabel.setText(currentSelectedGroup.getListUnit().get(0).getDamgeScore() + "");
			armorLabel.setText(currentSelectedGroup.getListUnit().get(0).getArmorScore() + "");
//			selectedArmy = currentSelectedGroup.getListUnit().get(0);

			if (currentSelectedGroup.getGroupType() == BuildingAndUnit.Type.BuildingBarrack) {
				selectingBuilding = (Building) currentSelectedGroup.getListUnit().get(0);
			}
			if (currentSelectedGroup.getGroupType() == BuildingAndUnit.Type.BuildingCastle) {
				selectingBuilding = (Building) currentSelectedGroup.getListUnit().get(0);
			}

		} else {
			//infoUnit.setVisible(false);
			infoUnit.setVisible(false);
		}
		if (currentSelectedGroup.getGroupType() == BuildingAndUnit.Type.UnitWorker) {
			workerPanel.setVisible(true);
		} else {
			workerPanel.setVisible(false);
		}

	}

	private void endGame(GameState newState) {
		GlobalGameOption.SOUND.getSound("game").stop();
		BuildingCastle.WAGES = 100;
		BuildingMine.WAGES = 100;
		BuildingAndUnit.BUILD_SPEED = 1;
		aiManager.stop();
		game.gameState = newState;
	}

	private void exeCheat(String str) {
		str = str.trim();
		boolean cheat = true;
		if ("free view".equalsIgnoreCase(str)) {
			isImmortal = true;
		} else if ("gold plz".equalsIgnoreCase(str)) {
			myTeam.setGold(myTeam.getGold() + 10000);
		} else if ("freeze".equalsIgnoreCase(str)) {
			aiManager.setIsPause(true);
		} else if ("go on".equalsIgnoreCase(str)) {
			aiManager.setIsPause(false);
		} else if ("gold rush".equalsIgnoreCase(str)) {
			BuildingCastle.WAGES = 10;
			BuildingMine.WAGES = 10;
		} else if ("boot".equalsIgnoreCase(str)) {
			BuildingAndUnit.BUILD_SPEED += 3;
		} else if ("default".equalsIgnoreCase(str)) {
			BuildingCastle.WAGES = 100;
			BuildingMine.WAGES = 100;
			BuildingAndUnit.BUILD_SPEED = 1;
		} else if ("war".equalsIgnoreCase(str)) {
			aiManager.setAttackIsPause(false);
			aiManager.setDevelopeIsPause(true);
		} else if ("peace".equalsIgnoreCase(str)) {
			aiManager.setAttackIsPause(true);
			aiManager.setDevelopeIsPause(false);
		} else if ("info".equalsIgnoreCase(str)) {
			System.out.println("\n====Info===");
			for (int i = 0; i < comTeams.length; i++) {

				ComputerTeam playerTeam = comTeams[i];
				System.out.println("========Team :" + playerTeam.getTeamId());
				System.out.println("Poputation :" + playerTeam.getPopulation()
						+ "/" + playerTeam.getPopulationLimit());
				System.out.println("Gold :" + playerTeam.getGold());
				System.out.println("Worker :" + playerTeam.getnWorker());
				System.out.println("Barrack :" + playerTeam.getnBarrack());
				System.out.println("Mine :" + playerTeam.getnMine());
			}
		} else {
			cheat = false;
		}

		if (cheat) {
			setMessage("Cheat activated");
		}
	}
}
